package demo1;

import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class Main2 {
    public static void main(String[] args) {
        /**
         * 读写锁
         */
        ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
        ReentrantReadWriteLock.ReadLock readLock = reentrantReadWriteLock.readLock();
        ReentrantReadWriteLock.WriteLock writeLock = reentrantReadWriteLock.writeLock();
        try {
            //读写加锁
            readLock.lock();
            //。。。。


        } finally {
            //读锁解锁
            readLock.unlock();
        }

        try {
            //写锁加锁
            writeLock.lock();

            //写锁解锁

        } finally {
            writeLock.unlock();
        }

    }
}
